/*
 * Info.cpp
 *
 *  Created on: 17/12/2011
 *      Author: george
 */

#include "info.h"




Info *Info::instance = 0;
#include <iomanip>
Info::Info()
{
	this->nmHosts			   = 0;
	this->nmSessionManagers	   = 0;

	this->nmCapturedPackets	   = 0;
	this->nmDiscartedPackets   = 0;
	this->nmDicartedTcpPackets = 0;

	this->nmUdpSessions		   = 0;
	this->nmTcpSessions		   = 0;
	this->nmIcmpErrorSessions  = 0;
	this->nmIcmpSessions	   = 0;

	gettimeofday(&this->inicioDaExecucao, 0);

}

Info *Info::getInstance()
{

	if ( !Info::instance )
	{
		Info::instance = new Info();
	}

	return Info::instance;
}

std::string Info::getExecutionTime()
{
	gettimeofday(&this->fimDaExecucao, 0);

	unsigned int  secondsElapseds       = this->fimDaExecucao.tv_sec  - this->inicioDaExecucao.tv_sec;
	int           minutesElapseds       = 0;
	int           microSecondsElapseds  = this->fimDaExecucao.tv_usec - this->inicioDaExecucao.tv_usec;

	if ( secondsElapseds > 0 )
	{
		if ( microSecondsElapseds < 0 )
		{
			secondsElapseds--;
			microSecondsElapseds = 1000000 - (microSecondsElapseds *-1);
		}
	}

	if ( secondsElapseds >= 60 )
	{
		minutesElapseds = secondsElapseds/60;
		secondsElapseds = secondsElapseds%60;
	}

	executionTime << minutesElapseds << "m" << secondsElapseds << "." << std::setprecision(3)  << (double)microSecondsElapseds/1000 << "s";

	return std::string(executionTime.str());

}

Info::~Info()
{
	// TODO Auto-generated destructor stub
}
